from os import mkdir, path
from networkx import draw_spring
import matplotlib.pyplot as plt
from rpy2 import robjects


class DataDraw:
    
    def __init__(self, drawDir):
        self.drawDir = drawDir
        if not path.exists(drawDir):
            mkdir(drawDir)
        
    def drawGraph(self, graph, name):
        draw_spring(graph)
        plt.savefig("%s/%s.png"%(self.drawDir, name))
        plt.clf() 
        
    def drawTiHistogram(self, vector, name):
        imageName = "%s/%s.png" % (self.drawDir, name)
        robjects.r.png(imageName, width = 400 , height = 300)
        robjects.r.hist(vector, main = name,xlab="", col="lightblue")
        robjects.r('dev.off()')     